package hy.controller;

import com.github.pagehelper.PageHelper;
import hy.beans.AjaxRestult;
import hy.cnfig.WebLog;
import hy.dao.EmpMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/emp")
@RestController
public class EmpController {
    @Autowired
    EmpMapper dao;



    @WebLog
    @GetMapping({"/emps","/emps/{pageNo}"})
    public AjaxRestult showEmps(@PathVariable(required = false) Integer pageNo){
        AjaxRestult rs=new AjaxRestult();
        if(pageNo!=null){
            PageHelper.startPage(pageNo, 2);
        }
        List list=dao.selectAllEmp();
        if(!list.isEmpty()){
            rs.setSuccess(true);
            rs.setData(list);
        }
        return rs;
    }

    @DeleteMapping("/emps")
    public AjaxRestult deleteEmpById(Integer id){
        AjaxRestult rs=new AjaxRestult();
        int r=dao.deleteEmpById(id);
        rs.setSuccess(r>0);
        return rs;
    }
}